# Contributor: Matthias Neugebauer <mtneug@mailbox.org>
# Contributor: omni <omni+alpine@hack.org>
# Maintainer: Matthias Neugebauer <mtneug@mailbox.org>
pkgname=nomad
pkgver=1.3.1 # remember to update _gitcommit below
_gitcommit=2b054e3
pkgrel=0
pkgdesc="easy-to-use, flexible, and performant workload orchestrator"
url="https://www.nomadproject.io/"
arch="all !riscv64"
# riscv64 limited by yarn/npm
license="MPL-2.0"
depends="
	cni-plugins
	"
makedepends="
	bash
	go
	go-bindata-assetfs
	linux-headers
	make
	"
subpackages="
	$pkgname-openrc
	"
options="net !check" # cannot produce environment for testing in CI
source="$pkgname-$pkgver.tar.gz::https://github.com/hashicorp/nomad/archive/v$pkgver.tar.gz
	nomad.initd
	nomad.confd
	server.hcl
	ui-remove-husky.patch
	"

# secfixes:
#   1.3.1-r0:
#     - CVE-2022-30324
#   1.2.6-r0:
#     - CVE-2022-24683
#     - CVE-2022-24684
#     - CVE-2022-24685
#     - CVE-2022-24686
#     - CVE-2021-44716
#     - CVE-2021-44717
#     - CVE-2021-43415
#     - CVE-2021-37218
#   1.1.1-r0:
#     - CVE-2021-32575
#   1.0.4-r0:
#     - CVE-2021-3283
#   0.12.7-r0:
#     - CVE-2020-28348
#     - CVE-2020-27195
#   0.11.1-r0:
#     - CVE-2020-10944
#   0.10.3-r0:
#     - CVE-2020-7218
#   0.9.6-r0:
#     - CVE-2019-12741
#     - CVE-2019-15928
#     - CVE-2019-16742
#   0.9.5-r0:
#     - CVE-2019-14802
#     - CVE-2019-14803
#   0.9.2-r0:
#     - CVE-2019-12618

export GOPATH="$srcdir"
export GOFLAGS="$GOFLAGS -trimpath -mod=readonly -modcacherw"
export GIT_COMMIT="$_gitcommit"

build() {
	go build -v -o bin/"$pkgname" \
		-ldflags "-X github.com/hashicorp/nomad/version.GitCommit='$pkgver'" \
		-tags "release"
}

check() {
	go test -timeout=15m "./..."
}

package() {
	install -m755 -D "$srcdir"/"$pkgname".initd "$pkgdir"/etc/init.d/"$pkgname"
	install -m644 -D "$srcdir"/"$pkgname".confd "$pkgdir"/etc/conf.d/"$pkgname"

	install -m755 -o root -g root -D bin/"$pkgname" "$pkgdir"/usr/sbin/"$pkgname"
	install -m640 -o root -g root -D "$srcdir"/server.hcl "$pkgdir"/etc/nomad.d/server.hcl
	install -m750 -o root -g root -d "$pkgdir"/var/lib/"$pkgname"
}

sha512sums="
9cf5f679e43e4d4ebda364fe4e72b6e293ebd866c334870323f71480ecb0c7cfa597c5635fa520de0c8f2d80bd176c42fa42379f63e4f439d7b4e174b595439a  nomad-1.3.1.tar.gz
ac969c81150ba57871c1f75f17c11d06ffc7bcc872882416c7c0d9d43f5e352ca1b7e7bfd75e32a9d01a826496c77a657dc298f5e048f85b4d9e85bc3afee51d  nomad.initd
a4fcc9f319926e8e5257dcc902cf3e1cbacd8bee82097b7a9719611d52037431a7e953a4b0fa90fc25475d2590cd14877c8e4c87bd909dd0099a754ba6f5063c  nomad.confd
c2ba7db5bb0858547bf346819945d24626ac761541f38350b40408e1b26227549f6aa4d6946baadbf856329c0ac9f81f84164597d11361224b62a1697f17e726  server.hcl
9fd25d413d78744a47e19a41dcd5150968da98b714451a03d562c67bf3a1a0d471b741713f4496eb37907e73e5f83dcc18cfe68abb23f1ffac0fe7d78295d4b6  ui-remove-husky.patch
"
